package com.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.api.model.User;
import com.api.service.UserService;

@Controller
public class UserController {

    @Autowired
    UserService userService;

    @ResponseBody
    @RequestMapping(value = "user/{id}", method = RequestMethod.GET)
    public User query(@PathVariable Long id) {
        return this.userService.query(id);
    }

    @ResponseBody
    @RequestMapping(value = "user/add", method = RequestMethod.POST)
    public User add(@RequestBody User user) {
        return this.userService.add(user);
    }

    @ResponseBody
    @RequestMapping(value = "user/update", method = RequestMethod.POST)
    public boolean update(@RequestBody User user) {
        return this.userService.update(user);
    }

    @ResponseBody
    @RequestMapping(value = "user/delete/{id}", method = RequestMethod.POST)
    public boolean delete(@PathVariable Long id) {
        return this.userService.delete(id);
    }

}
